﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eis51.CampanyCMS.FrameWork;
using Eis51.CampanyCMS.Business;

using Eis51.CampanyCMS.Business.Bus;

using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.CampanyCMS.Model;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.WebUI.Admin.BlockManager
{
    public partial class IssueInfo :BasePage
    {
        private int licd
        {
            get
            {
                if (Request["Licd"] != null)
                {
                    return int.Parse(Request["Licd"]);
                }
                return (int)Licd.CN;
            }
        }

        private string Code
        {
            get
            {
                return Request.QueryString["code"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }

        private void ShowData()
        {
            this.txtCode.Text = this.Code;
            BusIssueInfo c = BusIssueInfoBLL.GetInstance().GetBusIssueInfoByCode(Code, licd, AppContext.CurrentAdministrator.UserName);
            if (c != null)
            {
                UControl.CopyEntityToControl(this.Page.Form, c);
                if (!string.IsNullOrEmpty(c.Filename))
                {
                    // imgShow.ImageUrl = "/Img/UpLoadFile/" + c.Filename;
                    string file = "/" + AppContext.CurrentAdministrator.UserName + "/Img/UpLoadFile/" + c.Filename;
                    string strfile = "";

                    if (Eis51.CampanyCMS.FrameWork.Common.IsImg(file))
                    {
                        strfile = string.Format("<a target=_blank href='{0}' ><img src='{0}' width=50  height=50 border=0 ></a>", file);
                    }
                    else
                    {
                        strfile = string.Format("<a target=_blank href='{0}' >点击下载</a>", file);
                    }


                    lbTitle.Text = strfile;
                }
            }
             
        }
        private string SaveFile()
        {
            string sss = UploadFile.PostedFile.FileName;
            string patch = Server.MapPath("~/" + AppContext.CurrentAdministrator.UserName + "/Img/UpLoadFile/") + "\\";
            string fileName = FileListBLL.SaveFile(UploadFile, patch);
            return fileName;
        }



        private bool Save()
        {
            BusIssueInfo c = BusIssueInfoBLL.GetInstance().GetBusIssueInfoByCode(Code, licd, AppContext.CurrentAdministrator.UserName);
            UControl.CopyControlToEntity(this.Page.Form, c);

            string filename = SaveFile();
            if (filename != string.Empty)
            {
                c.Filename = filename;
            }
            BusIssueInfoBLL.GetInstance().SubMit(c);            
            return true;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Save();
            ShowData();
            BaseTools.ShowMessage(this.Page, "提交成功！");
        }
    }
}
